<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><div id="myscoll"></div><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Vue3+TS | 晚夜微雨问海棠のBlog</title><meta name="keywords" content="Vue3+TS"><meta name="author" content="晚夜微雨问海棠"><meta name="copyright" content="晚夜微雨问海棠"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Vue3 性能提升-更快如何更快？ 传统Virtual DOM的性能瓶颈   为什么不抛弃Virtual DOM ？ 高级场景下手写reader function 获得更强的表达力 生成代码更简洁 兼容Vue2.x  Vue所特有的 底层是Virtual DOM 上层包含大量静态信息的模板  Vue下一步需要做的 兼容手写 reader function  最大化利用静态模板信息  动静结合最简单">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue3+TS">
<meta property="og:url" content="http://example.com/posts/2d6701ec.html">
<meta property="og:site_name" content="晚夜微雨问海棠のBlog">
<meta property="og:description" content="Vue3 性能提升-更快如何更快？ 传统Virtual DOM的性能瓶颈   为什么不抛弃Virtual DOM ？ 高级场景下手写reader function 获得更强的表达力 生成代码更简洁 兼容Vue2.x  Vue所特有的 底层是Virtual DOM 上层包含大量静态信息的模板  Vue下一步需要做的 兼容手写 reader function  最大化利用静态模板信息  动静结合最简单">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/06/24/pCtuOKA.jpg">
<meta property="article:published_time" content="2023-06-14T10:11:56.000Z">
<meta property="article:modified_time" content="2023-06-24T02:56:59.805Z">
<meta property="article:author" content="晚夜微雨问海棠">
<meta property="article:tag" content="前端体系">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/06/24/pCtuOKA.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/posts/2d6701ec"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="manifest" href="/manifest.json"/><meta name="msapplication-TileColor" content="#49b1f5"/><link rel="apple-touch-icon" sizes="180x180" href="/img/siteicon/128.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/siteicon/32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/img/siteicon/16.png"/><link rel="mask-icon" href="/img/siteicon/128.png" color="#5bbad5"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":150},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":650,"languages":{"author":"作者: 晚夜微雨问海棠","link":"链接: ","source":"来源: 晚夜微雨问海棠のBlog","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Vue3+TS',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-24 10:56:59'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"> <link rel="stylesheet" href="/swiper/swiper.min.css"> <link rel="stylesheet" href="/swiper/swiperstyle.css"> <link rel="stylesheet" href="/css/rightMenu.css"> <link rel="stylesheet" href="/css/constrain.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/css/main.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-categories-card@1.0.0/lib/categorybar.css"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.min.css"/>
<style>#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags:before {content:"\A";
  white-space: pre;}#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags > .article-meta__separator{display:none}</style>
<link rel="stylesheet" href="https://cdn.cbd.int/anzhiyu-blog@2.0.3/css/runtime/runtime.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/swiperstyle.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/atom.xml" title="晚夜微雨问海棠のBlog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg" style="background:https://s1.ax1x.com/2023/06/24/pCtuOKA.jpg;background-attachment: local;background-position: center;background-size: cover;background-repeat: no-repeat;"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://img2.woyaogexing.com/2022/06/28/de1ce3dc65468fd4!400x400.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">97</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">31</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">17</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/bangumis/index.html"><i class="fa-fw fas fa-home"></i><span> 追番</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-envelope"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活馆</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://81.69.189.243:8082/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2023/06/24/pCtuOKA.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">晚夜微雨问海棠のBlog</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/bangumis/index.html"><i class="fa-fw fas fa-home"></i><span> 追番</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-envelope"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活馆</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://81.69.189.243:8082/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Vue3+TS</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-06-14T10:11:56.000Z" title="发表于 2023-06-14 18:11:56">2023-06-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-06-24T02:56:59.805Z" title="更新于 2023-06-24 10:56:59">2023-06-24</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>15分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Vue3+TS"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Vue3-性能提升-更快"><a href="#Vue3-性能提升-更快" class="headerlink" title="Vue3 性能提升-更快"></a>Vue3 性能提升-更快</h1><h2 id="如何更快？"><a href="#如何更快？" class="headerlink" title="如何更快？"></a>如何更快？</h2><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtuXDI.png" alt=""></p>
<h2 id="传统Virtual-DOM的性能瓶颈"><a href="#传统Virtual-DOM的性能瓶颈" class="headerlink" title="传统Virtual DOM的性能瓶颈"></a>传统Virtual DOM的性能瓶颈</h2><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtujbt.png" alt=""></p>
<p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtK9PS.png" alt=""></p>
<p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKC8g.png" alt=""></p>
<h2 id="为什么不抛弃Virtual-DOM-？"><a href="#为什么不抛弃Virtual-DOM-？" class="headerlink" title="为什么不抛弃Virtual DOM ？"></a>为什么不抛弃Virtual DOM ？</h2><ol>
<li>高级场景下手写<code>reader function</code> 获得更强的表达力</li>
<li>生成代码更简洁</li>
<li>兼容Vue2.x</li>
</ol>
<h2 id="Vue所特有的"><a href="#Vue所特有的" class="headerlink" title="Vue所特有的"></a>Vue所特有的</h2><ol>
<li>底层是Virtual DOM</li>
<li>上层包含大量静态信息的模板</li>
</ol>
<h2 id="Vue下一步需要做的"><a href="#Vue下一步需要做的" class="headerlink" title="Vue下一步需要做的"></a>Vue下一步需要做的</h2><ol>
<li>兼容手写 reader function </li>
<li>最大化利用静态模板信息</li>
</ol>
<h2 id="动静结合"><a href="#动静结合" class="headerlink" title="动静结合"></a>动静结合</h2><h3 id="最简单的情况"><a href="#最简单的情况" class="headerlink" title="最简单的情况"></a>最简单的情况</h3><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKP2Q.png" alt=""></p>
<h3 id="节点结构变化：v-if"><a href="#节点结构变化：v-if" class="headerlink" title="节点结构变化：v-if"></a>节点结构变化：v-if</h3><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKArn.png" alt=""></p>
<p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKArn.png" alt=""></p>
<h3 id="节点结构变化：v-for"><a href="#节点结构变化：v-for" class="headerlink" title="节点结构变化：v-for"></a>节点结构变化：v-for</h3><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKtIK.png" alt=""></p>
<h3 id="Block-tree-区块树"><a href="#Block-tree-区块树" class="headerlink" title="Block tree 区块树"></a>Block tree 区块树</h3><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKUPO.png" alt=""></p>
<ol>
<li>这样就突破了虚拟DOM的瓶颈</li>
</ol>
<h3 id="Before"><a href="#Before" class="headerlink" title="Before"></a>Before</h3><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKaGD.png" alt=""></p>
<h3 id="After"><a href="#After" class="headerlink" title="After"></a>After</h3><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKdRe.png" alt=""></p>
<h1 id="Vue3-Compiler-优化细节"><a href="#Vue3-Compiler-优化细节" class="headerlink" title="Vue3 Compiler - 优化细节"></a>Vue3 Compiler - 优化细节</h1><ol>
<li>推荐使用vue官方提供了演练场，演练对比：</li>
<li><code>https://template-explorer.vuejs.org/</code></li>
</ol>
<h1 id="Vue3-Composition-API-更好的逻辑复用"><a href="#Vue3-Composition-API-更好的逻辑复用" class="headerlink" title="Vue3 Composition API-更好的逻辑复用"></a>Vue3 Composition API-更好的逻辑复用</h1><h2 id="composition-API-示例"><a href="#composition-API-示例" class="headerlink" title="composition API 示例"></a>composition API 示例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">	<span class="title function_">setup</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="comment">// data</span></span><br><span class="line">		<span class="keyword">const</span> count = <span class="title function_">ref</span>(<span class="number">0</span>) <span class="comment">// ref：使值具有响应性，通过.value进行取值</span></span><br><span class="line">		<span class="comment">// computed</span></span><br><span class="line">		<span class="keyword">const</span> plusOne = <span class="title function_">computed</span>(<span class="function">() =&gt;</span> count.<span class="property">value</span> + <span class="number">1</span>)</span><br><span class="line">		<span class="comment">// method</span></span><br><span class="line">		<span class="keyword">const</span> <span class="title function_">increname</span> = (<span class="params"></span>) =&gt; count.<span class="property">value</span>++</span><br><span class="line">		<span class="comment">// watch</span></span><br><span class="line">		<span class="title function_">watch</span>(</span><br><span class="line">			<span class="function">() =&gt;</span> count.<span class="property">value</span> * <span class="number">2</span>,</span><br><span class="line">			<span class="function"><span class="params">v</span> =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(v)</span><br><span class="line">		)</span><br><span class="line">		<span class="comment">// lifecycle</span></span><br><span class="line">		<span class="title function_">onMounted</span>(<span class="function">() =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;onmounted&#x27;</span>))</span><br><span class="line">		<span class="comment">// 暴露给模板或渲染函数</span></span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			count</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ol>
<li>类似于，将<code>Vue2</code>的选项式<code>API</code>，转换为了函数</li>
</ol>
<h2 id="composition-API有什么好处？"><a href="#composition-API有什么好处？" class="headerlink" title="composition API有什么好处？"></a>composition API有什么好处？</h2><ol>
<li>更好的<code>TypeScript</code>类型推断支持</li>
<li>更灵活的逻辑复用能力</li>
<li><code>tree shaking</code>更友好</li>
</ol>
<h2 id="minxin-侦听鼠标位置"><a href="#minxin-侦听鼠标位置" class="headerlink" title="minxin 侦听鼠标位置"></a>minxin 侦听鼠标位置</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> mousePositionMixin = &#123;</span><br><span class="line">	<span class="title function_">data</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			<span class="attr">x</span>: <span class="number">0</span>,</span><br><span class="line">			<span class="attr">y</span>: <span class="number">0</span></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="title function_">mounted</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;mousemove&#x27;</span>, <span class="variable language_">this</span>.<span class="property">updata</span>)</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="title function_">destroyed</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;mousemove&#x27;</span>, <span class="variable language_">this</span>.<span class="property">updata</span>)</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="attr">methods</span>: &#123;</span><br><span class="line">		<span class="title function_">updata</span>(<span class="params">e</span>) &#123;</span><br><span class="line">			<span class="variable language_">this</span>.<span class="property">x</span> = e.<span class="property">pageX</span></span><br><span class="line">			<span class="variable language_">this</span>.<span class="property">y</span> = e.<span class="property">pageY</span></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="高阶组件-Higher-order-Component"><a href="#高阶组件-Higher-order-Component" class="headerlink" title="高阶组件(Higher-order Component)"></a>高阶组件(Higher-order Component)</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> list = <span class="title class_">WithMousePosition</span>(&#123;</span><br><span class="line">	<span class="attr">props</span>: [<span class="string">&#x27;x&#x27;</span>, <span class="string">&#x27;y&#x27;</span>],</span><br><span class="line">	<span class="attr">template</span>: <span class="string">`&lt;div&gt;Mouse Position:x&#123;&#123; x &#125;&#125; / y: &#123;&#123; y &#125;&#125;&lt;/div&gt;`</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h2 id="作用域插槽-Renderless-Components"><a href="#作用域插槽-Renderless-Components" class="headerlink" title="作用域插槽(Renderless Components)"></a>作用域插槽(Renderless Components)</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">mouse</span> <span class="attr">v-show</span>=<span class="string">&quot;&#123;x,y&#125;&quot;</span>&gt;</span></span><br><span class="line">    Mouse Position:x&#123;&#123;x&#125;&#125;/y&#123;&#123;y&#125;&#125; </span><br><span class="line"><span class="tag">&lt;/<span class="name">mouse</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="composition-API"><a href="#composition-API" class="headerlink" title="composition API"></a>composition API</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">useMousePosition</span>(<span class="params"></span>) &#123;</span><br><span class="line">	<span class="keyword">const</span> x = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line">	<span class="keyword">const</span> y = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">const</span> <span class="title function_">updata</span> = e =&gt; &#123;</span><br><span class="line">		x.<span class="property">value</span> = e.<span class="property">pageX</span></span><br><span class="line">		y.<span class="property">value</span> = e.<span class="property">pageY</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="title function_">onMounted</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">		<span class="variable language_">window</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;mousemove&#x27;</span>, updata)</span><br><span class="line">	&#125;)</span><br><span class="line"></span><br><span class="line">	<span class="title function_">onUnmounted</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">		<span class="variable language_">window</span>.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;mousemove&#x27;</span>, updata)</span><br><span class="line">	&#125;)</span><br><span class="line">	<span class="keyword">return</span> &#123; x, y &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span><br><span class="line">	<span class="attr">template</span>: <span class="string">`</span></span><br><span class="line"><span class="string">	&lt;div&gt;</span></span><br><span class="line"><span class="string">		Mouse Position:x&#123;&#123;x&#125;&#125;/y&#123;&#123;y&#125;&#125;</span></span><br><span class="line"><span class="string">	&lt;/div&gt;</span></span><br><span class="line"><span class="string">	`</span>,</span><br><span class="line">	<span class="title function_">setup</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="keyword">const</span> &#123; x, y &#125; = <span class="title function_">useMousePosition</span>()</span><br><span class="line">		<span class="keyword">return</span> &#123; x, y &#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h2 id="tree-shaking"><a href="#tree-shaking" class="headerlink" title="tree shaking"></a>tree shaking</h2><ol>
<li><code>Tree shaking</code>是一种在<code>JavaScript</code>模块化开发中用于优化代码的技术。</li>
<li>它的原理是通过静态分析代码，找出未被使用的代码块，并将其从最终的打包文件中删除，以减少文件大小和提高性能。</li>
<li><code>Tree shaking</code>通常与<code>ES6</code>模块化语法一起使用，因为ES6模块化语法是静态的，可以在编译时进行分析。</li>
<li>在<code>Webpack</code>等打包工具中，可以使用一些插件来实现<code>Tree shaking</code>，例如<code>UglifyJS</code>等。</li>
<li>需要注意的是，<code>Tree shaking</code>并不是万能的，有些情况下可能会出现误删或不准确的情况，因此在使用时还是需要谨慎。</li>
</ol>
<h1 id="Vue3-新特性与争议"><a href="#Vue3-新特性与争议" class="headerlink" title="Vue3 新特性与争议"></a>Vue3 新特性与争议</h1><h2 id="新特性"><a href="#新特性" class="headerlink" title="新特性"></a>新特性</h2><ol>
<li>composition API<ol>
<li>ref &amp; reactive</li>
<li>新的生命周期函数</li>
<li>computed 和 watch</li>
<li>Hooks</li>
</ol>
</li>
<li>内置组件<ol>
<li>Tleport</li>
<li>Suspense</li>
</ol>
</li>
</ol>
<h2 id="争议"><a href="#争议" class="headerlink" title="争议"></a>争议</h2><ol>
<li><code>&lt;script setup&gt; 与 ref: 设计？</code></li>
</ol>
<h2 id="composition-API-示例-1"><a href="#composition-API-示例-1" class="headerlink" title="composition API 示例"></a>composition API 示例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">	<span class="title function_">setup</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="comment">// data</span></span><br><span class="line">		<span class="keyword">const</span> count = <span class="title function_">ref</span>(<span class="number">0</span>) <span class="comment">// ref：使值具有响应性，通过.value进行取值</span></span><br><span class="line">		<span class="comment">// computed</span></span><br><span class="line">		<span class="keyword">const</span> plusOne = <span class="title function_">computed</span>(<span class="function">() =&gt;</span> count.<span class="property">value</span> + <span class="number">1</span>)</span><br><span class="line">		<span class="comment">// method</span></span><br><span class="line">		<span class="keyword">const</span> <span class="title function_">increname</span> = (<span class="params"></span>) =&gt; count.<span class="property">value</span>++</span><br><span class="line">		<span class="comment">// watch</span></span><br><span class="line">		<span class="title function_">watch</span>(</span><br><span class="line">			<span class="function">() =&gt;</span> count.<span class="property">value</span> * <span class="number">2</span>,</span><br><span class="line">			<span class="function"><span class="params">v</span> =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(v)</span><br><span class="line">		)</span><br><span class="line">		<span class="comment">// lifecycle</span></span><br><span class="line">		<span class="title function_">onMounted</span>(<span class="function">() =&gt;</span> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;onmounted&#x27;</span>))</span><br><span class="line">		<span class="comment">// 暴露给模板或渲染函数</span></span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			count</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="搭建-Vue3-开发环境"><a href="#搭建-Vue3-开发环境" class="headerlink" title="搭建 Vue3 开发环境"></a>搭建 Vue3 开发环境</h1><h2 id="准备物料"><a href="#准备物料" class="headerlink" title="准备物料"></a>准备物料</h2><ol>
<li>node 10+</li>
<li>HBuilderX / VSCode</li>
<li>@vue/cli4.5.13</li>
</ol>
<h1 id="vue3-响应性-reactive"><a href="#vue3-响应性-reactive" class="headerlink" title="vue3 响应性 reactive"></a>vue3 响应性 reactive</h1><h2 id="reactive"><a href="#reactive" class="headerlink" title="reactive"></a>reactive</h2><ol>
<li>返回对象的响应式副本。</li>
<li><code>function reactive&lt;T extends object&gt;(target: T): UnwrapNestedRefs&lt;T&gt;</code></li>
<li><code>reactive</code>一般都会搭配<code>toRefs</code>来进行使用</li>
<li>响应式转换是“深层”的：它会影响到所有嵌套的属性。</li>
<li>一个响应式对象也将深层地解包任何 <a target="_blank" rel="noopener" href="https://cn.vuejs.org/api/reactivity-core.html#ref">ref</a> 属性，同时保持响应性。</li>
<li>值得注意的是，当访问到某个响应式数组或 <code>Map</code> 这样的原生集合类型中的 ref 元素时，不会执行 ref 的解包。</li>
<li>若要避免深层响应式转换，只想保留对这个对象顶层次访问的响应性，请使用 <a target="_blank" rel="noopener" href="https://cn.vuejs.org/api/reactivity-advanced.html#shallowreactive">shallowReactive()</a> 作替代。</li>
<li>返回的对象以及其中嵌套的对象都会通过 <code>ES Proxy</code>包裹，因此<code>不等于</code>源对象，建议只使用响应式代理，避免使用原始对象。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = <span class="title function_">reactive</span>(&#123; <span class="attr">count</span>: <span class="number">0</span> &#125;)</span><br><span class="line">obj.<span class="property">count</span>++</span><br></pre></td></tr></table></figure>
<h2 id="toRefs"><a href="#toRefs" class="headerlink" title="toRefs"></a>toRefs</h2><ol>
<li>将响应式对象转换为普通对象，其中结果对象的每个 property 都是指向原始对象相应 property 的ref。</li>
<li>将一个响应式对象转换为一个普通对象，这个普通对象的每个属性都是指向源对象相应属性的 ref。每个单独的 ref 都是使用 toRef() 创建的。</li>
<li>toRefs：作用 返回一个结果对象{}，对象中的数据是响应性的，例如：{count: ref(0)}，</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> state = <span class="title function_">reactive</span>(&#123;</span><br><span class="line">  <span class="attr">foo</span>: <span class="number">1</span>,</span><br><span class="line">  <span class="attr">bar</span>: <span class="number">2</span></span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> stateAsRefs = <span class="title function_">toRefs</span>(state)</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">stateAsRefs 的类型：&#123;</span></span><br><span class="line"><span class="comment">  foo: Ref&lt;number&gt;,</span></span><br><span class="line"><span class="comment">  bar: Ref&lt;number&gt;</span></span><br><span class="line"><span class="comment">&#125;</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 这个 ref 和源属性已经“链接上了”</span></span><br><span class="line">state.<span class="property">foo</span>++</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(stateAsRefs.<span class="property">foo</span>.<span class="property">value</span>) <span class="comment">// 2</span></span><br><span class="line"></span><br><span class="line">stateAsRefs.<span class="property">foo</span>.<span class="property">value</span>++</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(state.<span class="property">foo</span>) <span class="comment">// 3</span></span><br></pre></td></tr></table></figure>
<ol>
<li>当从组合式函数中返回响应式对象时，<code>toRefs</code> 相当有用。使用它，消费者组件可以解构/展开返回的对象而不会失去响应性：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">useFeatureX</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="keyword">const</span> state = <span class="title function_">reactive</span>(&#123;</span><br><span class="line">    <span class="attr">foo</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="attr">bar</span>: <span class="number">2</span></span><br><span class="line">  &#125;)</span><br><span class="line"></span><br><span class="line">  <span class="comment">// ...基于状态的操作逻辑</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 在返回时都转为 ref</span></span><br><span class="line">  <span class="keyword">return</span> <span class="title function_">toRefs</span>(state)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 可以解构而不会失去响应性</span></span><br><span class="line"><span class="keyword">const</span> &#123; foo, bar &#125; = <span class="title function_">useFeatureX</span>()</span><br></pre></td></tr></table></figure>
<ol>
<li><code>toRefs</code> 在调用时只会为源对象上可以枚举的属性创建 ref。如果要为可能还不存在的属性创建 ref，请改用 toRef。</li>
</ol>
<h2 id="ref"><a href="#ref" class="headerlink" title="ref()"></a>ref()</h2><ol>
<li>接受一个内部值，返回一个响应式的、可更改的 ref 对象，此对象只有一个指向其内部值的属性 <code>.value</code></li>
<li>ref 对象是可更改的，也就是说你可以为 <code>.value</code> 赋予新的值。</li>
<li>它也是响应式的，即所有对 <code>.value</code> 的操作都将被追踪，并且写操作会触发与之相关的副作用。</li>
<li>如果将一个对象赋值给 ref，那么这个对象将通过 reactive() 转为具有深层次响应式的对象。</li>
<li>这也意味着如果对象中包含了嵌套的 ref，它们将被深层地解包。</li>
<li>若要避免这种深层次的转换，请使用 shallowRef() 来替代。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> count = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(count.<span class="property">value</span>) <span class="comment">// 0</span></span><br><span class="line"></span><br><span class="line">count.<span class="property">value</span>++</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(count.<span class="property">value</span>) <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>
<h2 id="computed"><a href="#computed" class="headerlink" title="computed()"></a>computed()</h2><ol>
<li>接受一个 getter 函数，返回一个只读的响应式 ref 对象。该 ref 通过 <code>.value</code> 暴露 getter 函数的返回值。它也可以接受一个带有 <code>get</code> 和 <code>set</code> 函数的对象来创建一个可写的 ref 对象。</li>
<li>实例：</li>
<li>创建一个只读的计算属性 ref：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> count = <span class="title function_">ref</span>(<span class="number">1</span>)</span><br><span class="line"><span class="keyword">const</span> plusOne = <span class="title function_">computed</span>(<span class="function">() =&gt;</span> count.<span class="property">value</span> + <span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(plusOne.<span class="property">value</span>) <span class="comment">// 2</span></span><br><span class="line"></span><br><span class="line">plusOne.<span class="property">value</span>++ <span class="comment">// 错误</span></span><br></pre></td></tr></table></figure>
<ol>
<li>创建一个可写的计算属性 ref：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> count = <span class="title function_">ref</span>(<span class="number">1</span>)</span><br><span class="line"><span class="keyword">const</span> plusOne = <span class="title function_">computed</span>(&#123;</span><br><span class="line">  <span class="attr">get</span>: <span class="function">() =&gt;</span> count.<span class="property">value</span> + <span class="number">1</span>,</span><br><span class="line">  <span class="attr">set</span>: <span class="function">(<span class="params">val</span>) =&gt;</span> &#123;</span><br><span class="line">    count.<span class="property">value</span> = val - <span class="number">1</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">plusOne.<span class="property">value</span> = <span class="number">1</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(count.<span class="property">value</span>) <span class="comment">// 0</span></span><br></pre></td></tr></table></figure>
<h2 id="总结："><a href="#总结：" class="headerlink" title="总结："></a>总结：</h2><ol>
<li>rest参数…: 也就是解构</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;h1&gt;&#123;&#123; count &#125;&#125;&lt;/h1&gt;</span><br><span class="line">	&lt;h1&gt;&#123;&#123; double &#125;&#125;&lt;/h1&gt;</span><br><span class="line">	&lt;button type=&quot;button&quot; @click=&quot;increase&quot;&gt;button&lt;/button&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script lang=&quot;ts&quot;&gt;</span><br><span class="line">import &#123; computed, defineComponent, reactive, toRefs &#125; from &#x27;vue&#x27;</span><br><span class="line"></span><br><span class="line">interface DataProps &#123;</span><br><span class="line">	count: number</span><br><span class="line">	double: number</span><br><span class="line">	increase: () =&gt; void</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">export default defineComponent(&#123;</span><br><span class="line">	name: &#x27;App&#x27;,</span><br><span class="line">	setup() &#123;</span><br><span class="line">		// reactive一般都会搭配toRefs来进行使用</span><br><span class="line">		const data: DataProps = reactive(&#123;</span><br><span class="line">			count: 0,</span><br><span class="line">			double: computed(() =&gt; data.count * 2),</span><br><span class="line">			increase: () =&gt; &#123;</span><br><span class="line">				data.count++</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;)</span><br><span class="line">		// toRefs：作用 返回一个结果对象&#123;&#125;，对象中的数据是响应性的，例如：&#123;count: ref(0)&#125;，</span><br><span class="line">		const state = toRefs(data)</span><br><span class="line">		// rest参数...: 也就是解构</span><br><span class="line">		return &#123;</span><br><span class="line">			...state</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<h1 id="Object-defineProperty-vs-Proxy"><a href="#Object-defineProperty-vs-Proxy" class="headerlink" title="Object.defineProperty vs Proxy"></a>Object.defineProperty vs Proxy</h1><h2 id="知乎网友"><a href="#知乎网友" class="headerlink" title="知乎网友"></a>知乎网友</h2><ol>
<li>Vue2.x为什么不监听数组下标的变化？</li>
<li>参考了很多博主的推文，自己也去尝试了一下，Object.defineProperty是可以做到监听数组的索引值变化，来做getter和setter的。</li>
</ol>
<h2 id="Vue2-响应式"><a href="#Vue2-响应式" class="headerlink" title="Vue2 响应式"></a>Vue2 响应式</h2><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKrqI.png" alt=""></p>
<h2 id="Vue2-对数组处理"><a href="#Vue2-对数组处理" class="headerlink" title="Vue2 对数组处理"></a>Vue2 对数组处理</h2><ol>
<li>由于 JavaScript 的限制，Vue 不能检测数组和对象的变化。</li>
<li>尽管如此我们还是有一些办法来回避这些限制并保证它们的响应性。</li>
<li>代理原型对象</li>
</ol>
<p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtKyZt.png" alt=""></p>
<h2 id="知乎网友-1"><a href="#知乎网友-1" class="headerlink" title="知乎网友"></a>知乎网友</h2><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtK6dP.png" alt=""></p>
<h2 id="proxy"><a href="#proxy" class="headerlink" title="proxy"></a>proxy</h2><ol>
<li>Proxy 可以理解成，在目标对象之前架设一层 拦截，外界对该对象的访问，都必须先通过这层拦截，因此提供了一种机制，可以对外界的访问进行过滤和改写。</li>
<li>实例：</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> source = [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>]</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> wrapped = <span class="keyword">new</span> <span class="title class_">Proxy</span>(source, &#123;</span><br><span class="line">	<span class="title function_">get</span>(<span class="params">target, key, receiver</span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;我侦测到您想对数组下标&#x27;</span> + key + <span class="string">&#x27;进行操作&#x27;</span>)</span><br><span class="line">		<span class="keyword">return</span> <span class="title class_">Reflect</span>.<span class="title function_">get</span>(target, key, receiver)</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="title function_">set</span>(<span class="params">target, key, value, receiver</span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;我侦测到您想对数组下标&#x27;</span> + key + <span class="string">&#x27;进行赋值操作&#x27;</span>)</span><br><span class="line">		<span class="keyword">return</span> <span class="title class_">Reflect</span>.<span class="title function_">set</span>(target, key, value, receiver)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">wrapped[<span class="number">0</span>]</span><br><span class="line">wrapped[<span class="number">0</span>] = <span class="number">5</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><ol>
<li>Object.defineProperty 是对 对象属性的劫持</li>
<li>Proxy 是对整个对象劫持</li>
<li>Object.defineProperty 需要手动绑定 响应式对象新增属性的响应性。</li>
<li>Proxy 能侦测对象新增属性并实时响应。</li>
<li>Object.defineProperty 无法侦测数组对象的变化 需要手动设置代理原型</li>
<li>Proxy 能监听数组</li>
<li>Object.defineProperty  启动就递归   不管对象嵌套多深都把链路上的propery转化为响应式的。</li>
<li>Proxy 只在 getter 时才进行对象下一层属性的劫持</li>
<li>Object.defineProperty  无兼容性问题</li>
<li>Proxy 有兼容性问题 (IE)</li>
</ol>
<h1 id="Vue3-Lifecycle-Hooks"><a href="#Vue3-Lifecycle-Hooks" class="headerlink" title="Vue3  Lifecycle  Hooks"></a>Vue3  Lifecycle  Hooks</h1><h2 id="什么是Vue的生命周期钩子"><a href="#什么是Vue的生命周期钩子" class="headerlink" title="什么是Vue的生命周期钩子"></a>什么是Vue的生命周期钩子</h2><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtlMRS.png" alt=""></p>
<h2 id="4个事件"><a href="#4个事件" class="headerlink" title="4个事件"></a>4个事件</h2><ol>
<li>组件创建</li>
<li>组件挂载</li>
<li>数据更新</li>
<li>组件销毁</li>
</ol>
<h2 id="9个钩子"><a href="#9个钩子" class="headerlink" title="9个钩子"></a>9个钩子</h2><ol>
<li>除了beforeCreate和created（被 setup 方法本身代替），共有9个Options API生命周期相对应的方法可以在setup中使用。<ol>
<li>onBeforeMount——挂载开始前调用</li>
<li>onMount——挂载后调用</li>
<li>onBeforeUpdate——当响应数据改变，且重新渲染前调用</li>
<li>onUpdated——重新渲染后调用</li>
<li>onBeforeUnmount——Vue实例销毁前调用</li>
<li>onUnmounted——实例销毁后调用</li>
<li>onActivated——当keep-alive组件被激活时调用</li>
<li>onDeactivated——当keep-alive组件取消激活时调用</li>
<li>onErrorCaptured——从子组件中捕获错误时调用</li>
</ol>
</li>
</ol>
<h2 id="使用生命周期钩子函数"><a href="#使用生命周期钩子函数" class="headerlink" title="使用生命周期钩子函数"></a>使用生命周期钩子函数</h2><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtl1MQ.png" alt=""></p>
<h2 id="beforeCreate"><a href="#beforeCreate" class="headerlink" title="beforeCreate"></a>beforeCreate</h2><ol>
<li>beforeCreate对那些不需要分配数据的逻辑和API调用来说十分有用。如果我们此时对数据对象赋值，那么这些值将在状态初始化后丢失。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">	<span class="title function_">data</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			<span class="attr">val</span>: <span class="string">&#x27;hello&#x27;</span></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="title function_">beforeCreate</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Value of val is&#x27;</span> + <span class="variable language_">this</span>.<span class="property">val</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="created"><a href="#created" class="headerlink" title="created"></a>created</h2><ol>
<li>created 对需要处理响应式数据读/写时非常有用。举个例子，如果你需要完成一个API调用并存储它的值，那么你应该将它写在这里。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">	<span class="title function_">data</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			<span class="attr">val</span>: <span class="string">&#x27;hello&#x27;</span></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="title function_">created</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Value of val is&#x27;</span> + <span class="variable language_">this</span>.<span class="property">val</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="Vue3-setup"><a href="#Vue3-setup" class="headerlink" title="Vue3  setup"></a>Vue3  setup</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; ref &#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">	<span class="title function_">setup</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="keyword">const</span> val = <span class="title function_">ref</span>(<span class="string">&#x27;hello&#x27;</span>)</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;Value of val is&#x27;</span> + val.<span class="property">value</span>)</span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			val</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="beforeMount-VS-onBeforeMount"><a href="#beforeMount-VS-onBeforeMount" class="headerlink" title="beforeMount VS onBeforeMount"></a>beforeMount VS onBeforeMount</h2><ol>
<li>在组件DOM实际渲染和挂载前触发。</li>
<li>在此阶段，根元素（root element）还未存在。在Options API中，可以通过this.$el访问根元素。而在Composition API中，你必需通过ref来访问根元素。</li>
</ol>
<h2 id="mounted-vs-onMounted"><a href="#mounted-vs-onMounted" class="headerlink" title="mounted vs onMounted"></a>mounted vs onMounted</h2><ol>
<li>在<code>Options API</code>中，我们使用<code>this.$el</code>访问<code>DOM</code>。<br>而在<code>Composition API</code>的生命周期钩子中，我们需要借助<code>ref</code>去访问相应<code>DOM</code>。</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;div ref=&quot;root&quot;&gt;Hello Root&lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">	import &#123; ref, onBeforeMount &#125; from &#x27;vue&#x27;</span><br><span class="line">	export default &#123;</span><br><span class="line">		setup() &#123;</span><br><span class="line">			const val = ref(null)</span><br><span class="line">			onBeforeMount(() =&gt; &#123;</span><br><span class="line">				console.log(root.value)</span><br><span class="line">			&#125;)</span><br><span class="line">			return &#123;</span><br><span class="line">				root</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<h2 id="beforeUpdate-vs-onBeforeUpdate"><a href="#beforeUpdate-vs-onBeforeUpdate" class="headerlink" title="beforeUpdate  vs onBeforeUpdate"></a>beforeUpdate  vs onBeforeUpdate</h2><ol>
<li>在数据修改且组件重渲染之前执行，这是手动修改DOM的好地方。</li>
</ol>
<h2 id="updated-vs-onUpdated"><a href="#updated-vs-onUpdated" class="headerlink" title="updated vs onUpdated"></a>updated vs onUpdated</h2><ol>
<li>这些钩子很有用，但多数情况我们可能会通过监听器（watchers）去检测对应数据的改变。</li>
<li>因为监听器在副作用函数中提供数据更改时的旧值和新值。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; ref, onBeforeUpdate, onUpdated &#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">	<span class="title function_">setup</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="keyword">const</span> count = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line">		<span class="keyword">const</span> val = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line">		<span class="title function_">onBeforeUpdate</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">			count.<span class="property">value</span>++</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;beforeupdate&#x27;</span>, count.<span class="property">value</span>)</span><br><span class="line">		&#125;)</span><br><span class="line">		<span class="title function_">onUpdated</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;updated() val:&#x27;</span> + val.<span class="property">value</span>)</span><br><span class="line">		&#125;)</span><br><span class="line">		<span class="keyword">return</span> &#123;</span><br><span class="line">			count,</span><br><span class="line">			val</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="beforeUnmount-vs-onBeforeUnmounted"><a href="#beforeUnmount-vs-onBeforeUnmounted" class="headerlink" title="beforeUnmount vs onBeforeUnmounted"></a>beforeUnmount vs onBeforeUnmounted</h2><ol>
<li>触发在组件开始销毁之前，在此会进行绝大多数的清理工作。在此阶段，你的组件仍然拥有所有的功能，任何东西都还未被销毁。</li>
</ol>
<h2 id="unmounted-vs-onUnmounted"><a href="#unmounted-vs-onUnmounted" class="headerlink" title="unmounted vs onUnmounted"></a>unmounted vs onUnmounted</h2><ol>
<li>此时，大多数组件和它的属性已经销毁，所以你能做的不多。同样，我打印一段数据去确切观察发生了什么。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; onUnmounted &#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">	<span class="title function_">setup</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="comment">/* Composition API */</span></span><br><span class="line">		<span class="title function_">onUnmounted</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;onmounted&#x27;</span>)</span><br><span class="line">		&#125;)</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="title function_">unmounted</span>(<span class="params"></span>) &#123;</span><br><span class="line">		<span class="comment">/* Options API */</span></span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;unmounted&#x27;</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="Vue3-Debug-Hooks"><a href="#Vue3-Debug-Hooks" class="headerlink" title="Vue3 Debug Hooks"></a>Vue3 Debug Hooks</h2><ol>
<li>Vue3为我们提供了两个调试时的钩子：<ol>
<li>onRenderTracked</li>
<li>onRenderTriggered</li>
</ol>
</li>
<li>这两个事件都携带一个DebuggerEvent参数，以允许我们获悉是什么触发了Vue实例的重新渲染。</li>
</ol>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">	<span class="title function_">onRenderTriggered</span>(<span class="params">e</span>) &#123;</span><br><span class="line">		<span class="keyword">debugger</span></span><br><span class="line">		<span class="comment">// 检测什么依赖造成了组件的重新渲染</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="总结-1"><a href="#总结-1" class="headerlink" title="总结"></a>总结</h2><ol>
<li>无论是使用<code>Options API</code>还是<code>Composition API</code>，不能仅知道你能用什么生命周期，还要知道为什么使用它们。</li>
</ol>
<h1 id="vue3-watch-侦听器"><a href="#vue3-watch-侦听器" class="headerlink" title="vue3 watch 侦听器"></a>vue3 watch 侦听器</h1><ol>
<li>在Vue3中，watch和watchEffect都是用于监听数据变化的方法，但它们有一些区别。</li>
<li>watch是一个选项，可以在组件的选项中定义。</li>
<li>它接收两个参数：要监听的数据和回调函数。</li>
<li>当监听的数据发生变化时，回调函数会被调用。</li>
<li>watch还可以接收一些选项，例如deep、immediate等，用于控制监听的行为。</li>
<li>watchEffect是一个函数，可以在组件的setup函数中使用。它接收一个函数作为参数，这个函数中可以访问组件中的响应式数据。</li>
<li>当响应式数据发生变化时，watchEffect会自动重新运行这个函数。</li>
<li>watchEffect不需要指定要监听的数据，它会自动追踪函数中使用的响应式数据。</li>
<li>因此，watch适用于需要精细控制监听行为的情况，而watchEffect适用于需要自动追踪响应式数据变化的情况。</li>
<li>需要注意的是，watchEffect可能会比watch更加消耗性能，因为它会自动追踪所有使用的响应式数据。</li>
</ol>
<h1 id="Vue3-Setup的使用及模块化封装"><a href="#Vue3-Setup的使用及模块化封装" class="headerlink" title="Vue3 Setup的使用及模块化封装"></a>Vue3 Setup的使用及模块化封装</h1><ol>
<li><p>例：侦听鼠标点击事件</p>
</li>
<li><p>vue页面：引入自定义的文件，并解构赋值，直接使用即可</p>
</li>
<li>这种风格，代码突出一个干净，且有效的避免了命名冲突的问题，可维护性高</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">	&lt;h1&gt;x:&#123;&#123; x &#125;&#125;&lt;/h1&gt;</span><br><span class="line">	&lt;h1&gt;y:&#123;&#123; y &#125;&#125;&lt;/h1&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script lang=&quot;ts&quot; setup&gt;</span><br><span class="line">// 引入自定义的hooks</span><br><span class="line">import userMousePosition from &#x27;./hooks/userMousePorsion&#x27;</span><br><span class="line"></span><br><span class="line">// 通过结构赋值的形式，获取数据</span><br><span class="line">const &#123; x, y &#125; = userMousePosition()</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>
<ol>
<li>TS页面：注意，函数方法最后一定要return设置返回值，并导出函数方法</li>
</ol>
<figure class="highlight tsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; ref, onMounted, onUnmounted &#125; <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">userMousePosition</span>(<span class="params"></span>) &#123;</span><br><span class="line">	<span class="keyword">const</span> x = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line">	<span class="keyword">const</span> y = <span class="title function_">ref</span>(<span class="number">0</span>)</span><br><span class="line">	<span class="keyword">const</span> <span class="title function_">updateMouse</span> = (<span class="params">e: MouseEvent</span>) =&gt; &#123;</span><br><span class="line">		y.<span class="property">value</span> = e.<span class="property">pageY</span></span><br><span class="line">		x.<span class="property">value</span> = e.<span class="property">pageX</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">// 组件挂载的时候</span></span><br><span class="line">	<span class="title function_">onMounted</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">		<span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, updateMouse)</span><br><span class="line">	&#125;)</span><br><span class="line">	<span class="comment">// 组件销毁的时候</span></span><br><span class="line">	<span class="title function_">onUnmounted</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">		<span class="variable language_">document</span>.<span class="title function_">removeEventListener</span>(<span class="string">&#x27;click&#x27;</span>, updateMouse)</span><br><span class="line">	&#125;)</span><br><span class="line">	<span class="keyword">return</span> &#123;</span><br><span class="line">		x,</span><br><span class="line">		y</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 导出</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> userMousePosition</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="Vue3的Teleport"><a href="#Vue3的Teleport" class="headerlink" title="Vue3的Teleport"></a>Vue3的Teleport</h1><p><img src= "" data-lazy-src="https://s1.ax1x.com/2023/06/24/pCtltI0.png" alt=""></p>
<ol>
<li>这个时候就需要 <code>Teleport</code>上场，<code>Teleport</code>就是建立一个传送门。<code>Teleport</code>包裹的组件在表现层和其他组件没有什么差异，但渲染的东西就像经过传送门一样，出现在另外一个地方</li>
<li><code>Vue</code>鼓励我们通过<code>UI</code>和相关行为封装到组件中来构建UI。我们可以将他们嵌套在另一个内部，以构建一个组成应用程序<code>UI</code>的树</li>
<li>然而，有时组件模板的一部分逻辑上属于该组件，而从技术角度来看，最好将模板的这一部分移动到<code>DOM</code>中<code>Vue app</code>之外的其他位置</li>
<li><code>Teleport</code>有个很形象的翻译就是传送</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">晚夜微雨问海棠</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/posts/2d6701ec.html">http://example.com/posts/2d6701ec.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">晚夜微雨问海棠のBlog</a>！</span></div></div><div class="tag_share"><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/06/24/pCtuOKA.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://s1.ax1x.com/2022/11/15/zE9P7d.jpg" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/15/zE9P7d.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://s1.ax1x.com/2022/11/15/zE9ung.jpg" target="_blank"><img class="post-qr-code-img" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/15/zE9ung.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/954c8db1.html" title="Google_V8原理"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2023/06/14/pCn45LT.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-14</div><div class="title">Google_V8原理</div></div></a></div><div><a href="/posts/f418d067.html" title="H5基础"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNllfe.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-10-06</div><div class="title">H5基础</div></div></a></div><div><a href="/posts/3da79d5b.html" title="JavaScript入门"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2022/12/08/z2ar8O.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-10-21</div><div class="title">JavaScript入门</div></div></a></div><div><a href="/posts/f818a4a.html" title="JavaScript面向对象"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/06/xXrY34.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-06</div><div class="title">JavaScript面向对象</div></div></a></div><div><a href="/posts/50839dad.html" title="ECMAScript基础"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/09/zS8LRA.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-09</div><div class="title">ECMAScript基础</div></div></a></div><div><a href="/posts/3a5743c3.html" title="Node全栈"><img class="cover" src= "" data-lazy-src="https://s1.ax1x.com/2022/12/03/zrV6Q1.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-12-03</div><div class="title">Node全栈</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3-%E6%80%A7%E8%83%BD%E6%8F%90%E5%8D%87-%E6%9B%B4%E5%BF%AB"><span class="toc-number">1.</span> <span class="toc-text">Vue3 性能提升-更快</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E6%9B%B4%E5%BF%AB%EF%BC%9F"><span class="toc-number">1.1.</span> <span class="toc-text">如何更快？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BC%A0%E7%BB%9FVirtual-DOM%E7%9A%84%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88"><span class="toc-number">1.2.</span> <span class="toc-text">传统Virtual DOM的性能瓶颈</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E6%8A%9B%E5%BC%83Virtual-DOM-%EF%BC%9F"><span class="toc-number">1.3.</span> <span class="toc-text">为什么不抛弃Virtual DOM ？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue%E6%89%80%E7%89%B9%E6%9C%89%E7%9A%84"><span class="toc-number">1.4.</span> <span class="toc-text">Vue所特有的</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue%E4%B8%8B%E4%B8%80%E6%AD%A5%E9%9C%80%E8%A6%81%E5%81%9A%E7%9A%84"><span class="toc-number">1.5.</span> <span class="toc-text">Vue下一步需要做的</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%A8%E9%9D%99%E7%BB%93%E5%90%88"><span class="toc-number">1.6.</span> <span class="toc-text">动静结合</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%80%E7%AE%80%E5%8D%95%E7%9A%84%E6%83%85%E5%86%B5"><span class="toc-number">1.6.1.</span> <span class="toc-text">最简单的情况</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8A%82%E7%82%B9%E7%BB%93%E6%9E%84%E5%8F%98%E5%8C%96%EF%BC%9Av-if"><span class="toc-number">1.6.2.</span> <span class="toc-text">节点结构变化：v-if</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8A%82%E7%82%B9%E7%BB%93%E6%9E%84%E5%8F%98%E5%8C%96%EF%BC%9Av-for"><span class="toc-number">1.6.3.</span> <span class="toc-text">节点结构变化：v-for</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Block-tree-%E5%8C%BA%E5%9D%97%E6%A0%91"><span class="toc-number">1.6.4.</span> <span class="toc-text">Block tree 区块树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Before"><span class="toc-number">1.6.5.</span> <span class="toc-text">Before</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#After"><span class="toc-number">1.6.6.</span> <span class="toc-text">After</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3-Compiler-%E4%BC%98%E5%8C%96%E7%BB%86%E8%8A%82"><span class="toc-number">2.</span> <span class="toc-text">Vue3 Compiler - 优化细节</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3-Composition-API-%E6%9B%B4%E5%A5%BD%E7%9A%84%E9%80%BB%E8%BE%91%E5%A4%8D%E7%94%A8"><span class="toc-number">3.</span> <span class="toc-text">Vue3 Composition API-更好的逻辑复用</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#composition-API-%E7%A4%BA%E4%BE%8B"><span class="toc-number">3.1.</span> <span class="toc-text">composition API 示例</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#composition-API%E6%9C%89%E4%BB%80%E4%B9%88%E5%A5%BD%E5%A4%84%EF%BC%9F"><span class="toc-number">3.2.</span> <span class="toc-text">composition API有什么好处？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#minxin-%E4%BE%A6%E5%90%AC%E9%BC%A0%E6%A0%87%E4%BD%8D%E7%BD%AE"><span class="toc-number">3.3.</span> <span class="toc-text">minxin 侦听鼠标位置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6-Higher-order-Component"><span class="toc-number">3.4.</span> <span class="toc-text">高阶组件(Higher-order Component)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F%E6%8F%92%E6%A7%BD-Renderless-Components"><span class="toc-number">3.5.</span> <span class="toc-text">作用域插槽(Renderless Components)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#composition-API"><span class="toc-number">3.6.</span> <span class="toc-text">composition API</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#tree-shaking"><span class="toc-number">3.7.</span> <span class="toc-text">tree shaking</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3-%E6%96%B0%E7%89%B9%E6%80%A7%E4%B8%8E%E4%BA%89%E8%AE%AE"><span class="toc-number">4.</span> <span class="toc-text">Vue3 新特性与争议</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%96%B0%E7%89%B9%E6%80%A7"><span class="toc-number">4.1.</span> <span class="toc-text">新特性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%89%E8%AE%AE"><span class="toc-number">4.2.</span> <span class="toc-text">争议</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#composition-API-%E7%A4%BA%E4%BE%8B-1"><span class="toc-number">4.3.</span> <span class="toc-text">composition API 示例</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%90%AD%E5%BB%BA-Vue3-%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="toc-number">5.</span> <span class="toc-text">搭建 Vue3 开发环境</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%87%86%E5%A4%87%E7%89%A9%E6%96%99"><span class="toc-number">5.1.</span> <span class="toc-text">准备物料</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#vue3-%E5%93%8D%E5%BA%94%E6%80%A7-reactive"><span class="toc-number">6.</span> <span class="toc-text">vue3 响应性 reactive</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#reactive"><span class="toc-number">6.1.</span> <span class="toc-text">reactive</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#toRefs"><span class="toc-number">6.2.</span> <span class="toc-text">toRefs</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ref"><span class="toc-number">6.3.</span> <span class="toc-text">ref()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#computed"><span class="toc-number">6.4.</span> <span class="toc-text">computed()</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93%EF%BC%9A"><span class="toc-number">6.5.</span> <span class="toc-text">总结：</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Object-defineProperty-vs-Proxy"><span class="toc-number">7.</span> <span class="toc-text">Object.defineProperty vs Proxy</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9F%A5%E4%B9%8E%E7%BD%91%E5%8F%8B"><span class="toc-number">7.1.</span> <span class="toc-text">知乎网友</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue2-%E5%93%8D%E5%BA%94%E5%BC%8F"><span class="toc-number">7.2.</span> <span class="toc-text">Vue2 响应式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue2-%E5%AF%B9%E6%95%B0%E7%BB%84%E5%A4%84%E7%90%86"><span class="toc-number">7.3.</span> <span class="toc-text">Vue2 对数组处理</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9F%A5%E4%B9%8E%E7%BD%91%E5%8F%8B-1"><span class="toc-number">7.4.</span> <span class="toc-text">知乎网友</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#proxy"><span class="toc-number">7.5.</span> <span class="toc-text">proxy</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">7.6.</span> <span class="toc-text">总结</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3-Lifecycle-Hooks"><span class="toc-number">8.</span> <span class="toc-text">Vue3  Lifecycle  Hooks</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFVue%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90"><span class="toc-number">8.1.</span> <span class="toc-text">什么是Vue的生命周期钩子</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%E4%B8%AA%E4%BA%8B%E4%BB%B6"><span class="toc-number">8.2.</span> <span class="toc-text">4个事件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9%E4%B8%AA%E9%92%A9%E5%AD%90"><span class="toc-number">8.3.</span> <span class="toc-text">9个钩子</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90%E5%87%BD%E6%95%B0"><span class="toc-number">8.4.</span> <span class="toc-text">使用生命周期钩子函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#beforeCreate"><span class="toc-number">8.5.</span> <span class="toc-text">beforeCreate</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#created"><span class="toc-number">8.6.</span> <span class="toc-text">created</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue3-setup"><span class="toc-number">8.7.</span> <span class="toc-text">Vue3  setup</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#beforeMount-VS-onBeforeMount"><span class="toc-number">8.8.</span> <span class="toc-text">beforeMount VS onBeforeMount</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#mounted-vs-onMounted"><span class="toc-number">8.9.</span> <span class="toc-text">mounted vs onMounted</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#beforeUpdate-vs-onBeforeUpdate"><span class="toc-number">8.10.</span> <span class="toc-text">beforeUpdate  vs onBeforeUpdate</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#updated-vs-onUpdated"><span class="toc-number">8.11.</span> <span class="toc-text">updated vs onUpdated</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#beforeUnmount-vs-onBeforeUnmounted"><span class="toc-number">8.12.</span> <span class="toc-text">beforeUnmount vs onBeforeUnmounted</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#unmounted-vs-onUnmounted"><span class="toc-number">8.13.</span> <span class="toc-text">unmounted vs onUnmounted</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Vue3-Debug-Hooks"><span class="toc-number">8.14.</span> <span class="toc-text">Vue3 Debug Hooks</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93-1"><span class="toc-number">8.15.</span> <span class="toc-text">总结</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#vue3-watch-%E4%BE%A6%E5%90%AC%E5%99%A8"><span class="toc-number">9.</span> <span class="toc-text">vue3 watch 侦听器</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3-Setup%E7%9A%84%E4%BD%BF%E7%94%A8%E5%8F%8A%E6%A8%A1%E5%9D%97%E5%8C%96%E5%B0%81%E8%A3%85"><span class="toc-number">10.</span> <span class="toc-text">Vue3 Setup的使用及模块化封装</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue3%E7%9A%84Teleport"><span class="toc-number">11.</span> <span class="toc-text">Vue3的Teleport</span></a></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://s1.ax1x.com/2023/06/24/pCtuOKA.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2023 By 晚夜微雨问海棠</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" href="/archives/"><i class="fa-solid fa-archive"></i><span>文章归档</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>文章分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuNormal"><div class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简切换</span></div><div class="rightMenu-item" id="menu-darkmode"><i class="fa-solid fa-moon"></i><span>切换模式</span></div></div></div><div id="rightmenu-mask"></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: '',
      appKey: '',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><div class="aplayer no-destroy" data-id="7625372994" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div> <script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script> <script src="/swiper/swiper.min.js"></script> <script src="/swiper/swiperindex.js"></script> <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script> <script src="/js/title.js"></script> <script defer data-pjax src="/js/cat.js"></script> <script defer data-pjax src="/js/rightMenu.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show","#web_bg",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function history_calendar_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div>';
                console.log('已挂载history_calendar')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='/'|| '/' ==='all')){

            history_calendar_injector_config()
        } </script><script data-pjax  src="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.js"></script><script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/js/main.js"></script><script data-pjax>
    function butterfly_categories_card_injector_config(){
      var parent_div_git = document.getElementById('recent-posts');
      var item_html = '<style>li.categoryBar-list-item{width:24%;}.categoryBar-list{max-height: 190px;overflow:auto;}.categoryBar-list::-webkit-scrollbar{width:0!important}@media screen and (max-width: 650px){.categoryBar-list{max-height: 160px;}}</style><div class="recent-post-item" style="height:auto;width:100%;padding:0px;"><div id="categoryBar"><ul class="categoryBar-list"><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpicnew6.photophoto.cn%2F20120106%2Fhaimianbaobaotupian-10036689_1.jpg&amp;refer=http%3A%2F%2Fpicnew6.photophoto.cn&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648815&amp;t=a3deb15ddd7a38597964c3a05e519bd7);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/Asp-Net/&quot;);" href="javascript:void(0);">Asp.Net</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://npm.elemecdn.com/anzhiyu-blog@1.1.6/img/post/common/site-backgound.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/C-系列/&quot;);" href="javascript:void(0);">C#系列</a><span class="categoryBar-list-count">8</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13012860773%2F1000.jpg&amp;refer=http%3A%2F%2Finews.gtimg.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648865&amp;t=1d2f13b52a7e279e8801545f59eda4e7);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/Hexo重装记录/&quot;);" href="javascript:void(0);">Hexo重装记录</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202011%2F07%2F20201107183300_ac0c5.thumb.1000_0.jpeg&amp;refer=http%3A%2F%2Fc-ssl.duitang.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648887&amp;t=3d32c6b12a4cf12e5cec3585b79c1fc3);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/EF/&quot;);" href="javascript:void(0);">EF</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2F25%2Feb%2F1f%2F25eb1fd40b5a740c2b79e33f700806e5.jpg&amp;refer=http%3A%2F%2Fup.enterdesk.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665648908&amp;t=6425ee3bd166b0f5c5ffa6fb18b6937b);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/LOL/&quot;);" href="javascript:void(0);">LOL</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Flmg.jj20.com%2Fup%2Fallimg%2Ftx26%2F36080017392073.jpg&amp;refer=http%3A%2F%2Flmg.jj20.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665650136&amp;t=5cc414d0ee58c9e285218d92f6a95513);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/idea/&quot;);" href="javascript:void(0);">idea</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn10%2F320%2Fw700h420%2F20180907%2F5116-hitesuz6599636.jpg&amp;refer=http%3A%2F%2Fn.sinaimg.cn&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1665650004&amp;t=6a304aa9cc7435ec1d148b8f99092bc0);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/世界/&quot;);" href="javascript:void(0);">世界</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxCi6.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/世界见闻录/&quot;);" href="javascript:void(0);">世界见闻录</a><span class="categoryBar-list-count">8</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxFzD.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/前端体系/&quot;);" href="javascript:void(0);">前端体系</a><span class="categoryBar-list-count">19</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxnot.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/副业/&quot;);" href="javascript:void(0);">副业</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxMJf.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/文案/&quot;);" href="javascript:void(0);">文案</a><span class="categoryBar-list-count">6</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxQW8.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/办公日常/&quot;);" href="javascript:void(0);">办公日常</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAx3Qg.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/朝花夕拾/&quot;);" href="javascript:void(0);">朝花夕拾</a><span class="categoryBar-list-count">12</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(https://s1.ax1x.com/2022/11/15/zAxYes.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/前端/&quot;);" href="javascript:void(0);">前端</a><span class="categoryBar-list-count">20</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(undefined);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/杂七杂八/&quot;);" href="javascript:void(0);">杂七杂八</a><span class="categoryBar-list-count">7</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(undefined);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/简书/&quot;);" href="javascript:void(0);">简书</a><span class="categoryBar-list-count">5</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(undefined);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/游戏/&quot;);" href="javascript:void(0);">游戏</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li></ul></div></div>';
      console.log('已挂载butterfly_categories_card')
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
      }
    if( document.getElementById('recent-posts') && (location.pathname ==='/'|| '/' ==='all')){
    butterfly_categories_card_injector_config()
    }
  </script><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src= "" data-lazy-src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var qweather_key = '41ea442da35546559913a6a5d54163b2';
  var gaud_map_key = '6b62fbebf584b9a22a85bfccbf90335e';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '114.35,34.79';
  var clock_default_rectangle_enable = 'true';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" data-title="博客框架为Hexo_v5.4.0" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px" data-title="主题版本Butterfly_v4.2.2" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" alt=""/></a><a class="github-badge" target="_blank" href="https://www.jsdelivr.com/" style="margin-inline:5px" data-title="本站使用JsDelivr为静态资源提供CDN加速" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&amp;logo=jsDelivr" alt=""/></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px" data-title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可" title=""><img src= "" data-lazy-src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" alt=""/></a></p>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="/js/runtime/runtime.min.js"></script><script data-pjax>
  function butterfly_swiper_injector_config(){
    var parent_div_git = document.getElementById('recent-posts');
    var item_html = '<div class="recent-post-item swiper_container_card" style="height: auto;width: 100%"><div id="random"><div id="random-banner"><canvas id="peoplecanvas"></canvas></div><a id="random-hover" style="width:100%;height:auto;" href="javascript:toRandomPost()" rel="external nofollow noreferrer" one-link-mark="yes"><i class="fa fa-paper-plane" style="margin-left:10px"></i><div style="margin-left:10px">随便逛逛<i class="fa-solid fa-arrow-right" style="margin-left:10px"></i></div></a></div><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/67fcd28d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://img2.baidu.com/it/u=4087346614,241521689&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=JPEG?w=500&amp;h=333" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-19</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/67fcd28d.html&quot;);" href="javascript:void(0);" alt="">学生人到职业人_心态篇</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/67fcd28d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/8a73f76c.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/11/04/xLiBTA.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-11-04</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/8a73f76c.html&quot;);" href="javascript:void(0);" alt="">生活の奇思妙想☞2022</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/8a73f76c.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/14e5dae6.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/21/xcAQDH.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-11-12</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/14e5dae6.html&quot;);" href="javascript:void(0);" alt="">少年自负凌云笔</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/14e5dae6.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/9b7092b7.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNJbF0.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-13</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/9b7092b7.html&quot;);" href="javascript:void(0);" alt="">租房有感</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/9b7092b7.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/94bbc7d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNJLWT.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-25</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/94bbc7d.html&quot;);" href="javascript:void(0);" alt="">谷歌收藏</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/94bbc7d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/3b350f14.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://s1.ax1x.com/2022/10/11/xNJJd1.jpg" alt="" onerror="this.src=https://cdn.cbd.int/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2022-09-13</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/3b350f14.html&quot;);" href="javascript:void(0);" alt="">阳光不燥、微风正好</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/3b350f14.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载butterfly_swiper')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'undefined'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_swiper_injector_config();
  }
  else if (epage === cpage){
    butterfly_swiper_injector_config();
  }
  </script><script defer src="https://npm.elemecdn.com/anzhiyu-blog@1.1.6/js/swiper.min.js"></script><script defer data-pjax src="https://cdn.cbd.int/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/swiper_init.js"></script><script data-pjax src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/gsap/3.9.1/gsap.min.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper-anzhiyu@1.0.4/lib/people.min.js"></script><script async src="/anzhiyu/random.js"></script><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1.5s');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '30');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '200ms');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('flink-list-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__flipInY');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('flink-list-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__animated');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('article-sort-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__slideInRight');
    arr[i].setAttribute('data-wow-duration', '1.5s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('site-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__flipInY');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script><script async="async">var arr = document.getElementsByClassName('site-card');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__animated');
    arr[i].setAttribute('data-wow-duration', '3s');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://cdn.cbd.int/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://cdn.cbd.int/hexo-butterfly-wowjs/lib/wow_init.js"></script><script async src="/js/ali_font.js"></script><!-- hexo injector body_end end --><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/"});</script></body></html>